package com.nariano.server.utils.aop.timelogging;


import java.util.logging.Logger;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;


@Aspect
public class LogExecutionTimeAspect {
	
	private static Logger logger = Logger.getLogger(LogExecutionTimeAspect.class.getCanonicalName());
	
	@Pointcut("@annotation(com.nariano.server.utils.aop.timelogging.LogExecTime)")
	public void timeConsumingOperation() {}
	
	
	@Around("com.nariano.server.utils.aop.timelogging.LogExecutionTimeAspect.timeConsumingOperation()")
	 public Object logExecutionTime(ProceedingJoinPoint pjp) throws Throwable {
		
		long time = System.currentTimeMillis();
		
		
	    // start stopwatch
	    Object retVal = pjp.proceed();
	    // stop stopwatch
	    
	    logger.info(pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName() + "() executed in " +  (System.currentTimeMillis()- time) + " milliseconds" );
	    return retVal;
	  }
	
	
}
